package com.Advance.InnerClass_.anonymous_class;

import org.w3c.dom.ls.LSOutput;

//匿名内部用中基于类的使用。其不同于接口，基于类使用还需要一个参数列表
public class anonymous_class {
    public static void main(String[] args) {
        Outer02 outer02 = new Outer02();
        outer02.method();
        System.out.println("outer02的hashcode = "+outer02);
    }
}
class Outer02{
    private int a = 1;
    public void method() {
        father f = new father("kd") {//参数列表会传递给构造器
            int a = 8;
            @Override
            public void test() {
                System.out.println("匿名内部类重写test方法");
                System.out.println(a);
                System.out.println(Outer02.this.a);//Outer02.this就是外部类的一个对象
                //可以通过hascode值来验证
            }
        };
        System.out.println("Outer02.this.a的hashcode = " + Outer02.this);
        f.test();
        System.out.println("f的运行类型 = "+ f.getClass());
        //基于抽象类的匿名内部类
        abs a = new abs(){
            @Override
            void test() {
                System.out.println("抽象类中的test方法被调用");
            }
        };
        a.test();
        System.out.println("a的运行类型 = "+a.getClass());
    }
}
class father{
    public father(String name){
        System.out.println("接受到的name = " + name);
    }
    public void test(){
        System.out.println("father");
    }
}
abstract class abs{
    abstract void test();
}
